﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Page1.xaml
    /// </summary>
    public partial class Page1 : Page
    {
        public static class Myvar{
            public static string forca = Application.Current.Properties["forca"].ToString();
            public static string eforca = Application.Current.Properties["eforca"].ToString();
            public static string sorte = Application.Current.Properties["sorte"].ToString();
            public static int msor = int.Parse(sorte);
            public static int mfor=int.Parse(forca);
            public static int efor = int.Parse(eforca);
        }
        public Page1()
        {
            InitializeComponent();
            string pericia=Application.Current.Properties["pericia"].ToString();
            perbox.Text = pericia;
            forcabox.Text = Myvar.mfor.ToString();
            string sorte = Application.Current.Properties["sorte"].ToString();
            sorbox.Text = sorte;
            string epericia = Application.Current.Properties["epericia"].ToString();
            eperbox.Text = epericia;
            eforbox.Text =Myvar.efor.ToString();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var r1=new Random();
            var edados=r1.Next(2,13);
            var mdados=r1.Next(2,13);
            int eper = 0; int mper = 0;
            string forca = Application.Current.Properties["forca"].ToString();
            try { eper = Convert.ToInt16(eperbox.Text); mper = Convert.ToInt16(perbox.Text); }
            catch (FormatException)
            {
                result.Content = " not a number";
            }
            catch (OverflowException)
            {
                result.Content = "not  a valid number";
            }
            finally
            {

                var etot = edados + eper;
                var mtot = mdados + mper;

                if (etot < mtot)
                {Myvar.efor-=2;  result.Content = "WIN this round ,enemy stamina:"+Myvar.efor+" My stamina:"+Myvar.mfor; }
                else if (etot == mtot)
                { result.Content = "TIE"; }
                else
                { Myvar.mfor -= 2; result.Content = "LOSE this round,my stamina:" + Myvar.mfor+" Enemy stamina:"+Myvar.efor; }

                if (Myvar.efor < 1) { result2.Content = "You Win the Fight"; }
                else if (Myvar.mfor < 1) { result2.Content = "You Lost the Fight"; }

                fpro.Content = "Enemy:" + edados +" + "+ eper + " = " + etot + " Me:" + mdados +" + "+ mper + " = " + mtot;
            }            




        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
            Application.Current.Shutdown();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            var r1 = new Random();
            var mdados = r1.Next(2, 13);
            string res1 = result.Content.ToString();
            if(res1.Contains("WIN")==true)
            {
                if(mdados<=Myvar.msor){fpro.Content="You had Luck,"+"your dice roll:"+mdados +",your luck:"+Myvar.msor; 
                    Myvar.efor-=2;result.Content="You hit extra damage,my stamina:"+Myvar.mfor+" Enemy stamina:"+Myvar.efor;Myvar.msor-=1;}
                else {fpro.Content="You Had no luck,"+"your dice roll:"+mdados+",your luck:"+Myvar.msor;
                    result.Content="You Did not make any damage,mystamina:"+Myvar.mfor+" Enemy stamina:"+Myvar.efor;Myvar.msor-=1;}
            }
            else if (res1.Contains("LOSE") == true)
            {
                if (mdados <= Myvar.msor)
                {
                    fpro.Content = "You had Luck," + "your dice roll:" + mdados + ",your luck:" + Myvar.msor;
                    Myvar.mfor += 1; result.Content = "You have been hit with less damage:" + Myvar.mfor + " Enemy stamina:" + Myvar.efor; Myvar.msor -= 1;
                }
                else
                {
                    fpro.Content = "You Had no luck," + "your dice roll:" + mdados + ",your luck:" + Myvar.msor;
                    result.Content = "You Did not make any damage,mystamina:" + Myvar.mfor + " Enemy stamina:" + Myvar.efor; Myvar.msor -= 1;
                }
            }
            else { result.Content = "Cannot roll luck at this time!"; }
        }
    }
}
